import urllib,urllib2,re



def file_write(filename,data):
	f = open(filename,'w')
	f.write(data)
	f.close()

page = 1
url = 'http://www.qiushibaike.com/hot/page/' + str(page)
user_agent = 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'
headers = { 'User-Agent' : user_agent }
try:
	request = urllib2.Request(url,headers=headers)
	response = urllib2.urlopen(request)
	data = response.read().decode('utf-8')
	pattern = re.compile('<div class="author clearfix">.*?<h2>(.*?)</h2>.*?"content">(.*?)</div>.*?number">(.*?)</.*?number">(.*?)</.',re.S)
	items = re.findall(pattern,data)
	for item in items:
		pattern_span = re.compile('<span>(.*?)</span>')
		text = re.findall(pattern_span,item[1])
		print text[0]
except urllib2.URLError,e:
	if hasattr(e,'code'):
		print e.code
	if hasattr(e,'reason'):
		print e.reason





